﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Employees_EmpInsuranceBatch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void wgvType_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlNew.Items.Clear();
        ddlOld.Items.Clear();
        if (wgvType.SelectedValue != "-1")
        {
            tb.Visible = true;

            object[] ret = Srvtools.CliUtils.CallMethod("SEmployees", "GetCommInsurance", new object[] { wgvType.SelectedValue });
            if (ret[1] != null)
            {
                DataTable dt = ((DataSet)ret[1]).Tables[0];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ddlNew.Items.Add(new ListItem(dt.Rows[i]["InsuranceName"].ToString(), dt.Rows[i]["InsuranceId"].ToString()));
                    ddlOld.Items.Add(new ListItem(dt.Rows[i]["InsuranceName"].ToString(), dt.Rows[i]["InsuranceId"].ToString()));
                }
            }
        }
        else
        {
            tb.Visible = false;

        }
    }

    protected void wgvType_DataBound(object sender, EventArgs e)
    {
        wgvType.Items.Add(new ListItem("未选择", "-1"));
        wgvType.SelectedValue = "-1";
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        //parent.location.reload();return false



        if (ddlNew.SelectedValue != null && ddlOld.SelectedValue != null && ddlNew.SelectedValue != ddlOld.SelectedValue)
        {
            object[] ret = Srvtools.CliUtils.CallMethod("SEmployees", "UpdateEmpInsurance", new object[] { ddlNew.SelectedValue,ddlOld.SelectedValue });

            if ((bool)ret[1])
            {
                ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('替换成功！');parent.location='EmpInsurance.aspx'", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('替换失败！');", true);
            }
        }
    }
}
